namespace SimpleWebServices.Web.UI.Html.Elements
{
    using System;
    using System.Diagnostics.CodeAnalysis;
    using SimpleWebServices.Globalization;

    [SuppressMessage("Microsoft.Naming", "CA1724:TypeNamesShouldNotMatchNamespaces", Justification = "This naming is intentional.")]
    public sealed class TextString : IElement
    {
        public TextString()
            : this(null)
        {
        }

        public TextString(string value)
        {
            this.Value = value;
        }

        public string Value
        {
            get;
            set;
        }

        Name IElement.Id
        {
            get
            {
                return null;
            }

            set
            {
                throw new NotSupportedException();
            }
        }
        
        Names IElement.Class
        {
            get
            {
                return null;
            }

            set
            {
                throw new NotSupportedException();
            }
        }

        Language IElement.Language
        {
            get
            {
                return null;
            }

            set
            {
                throw new NotSupportedException();
            }
        }

        string IElement.Title
        {
            get
            {
                return null;
            }

            set
            {
                throw new NotSupportedException();
            }
        }

        IElement IElementSerializable.ToElement()
        {
                return this;
        }

        IElement IElementSerializable.Deserialize(string name, string type, string xml)
        {
            return null;
        }

        string IElementSerializable.Render()
        {
            string result = null;
            
            if (!string.IsNullOrEmpty(this.Value))
            {
                result = this.Value.Serialize().CreateNavigator().SelectSingleNode("//string").InnerXml;
            }

            return result;
        }

        public override string ToString()
        {
            return (this as IElementSerializable).Render();
        }
    }
}